/**
 * Created by novem on 15/9/25.
 */
window.onload=function(){
    var url = getUrl();
    var userId = getUserId();
    $(".ui-header-right").on("click", function () {
                             var star= $("#star li.on").length;
                             var comment = $("#comment").val();
                             var urlList = getPics();
                             var id= $.getUrlParam("id");
                             var param = $.getUrlParam("param");
                             if(star == 0){
                             showToast("总体评价需要打分哦~");
                             return;
                             }
                             if(comment == ""){
                             showToast("点评内容不能为空哦~");
                             return;
                             }
                             if(urlList == ""){
                             showToast("请至少上传一张图片~");
                             return;
                             }
                             if(param=="rcar"){
                             if(comment.length<=20){
                             $.jsonp({
                                     url: 'http://'+url+'/api/rcar/comment',
                                     data: {star:star,comment:comment,rcarId:id,urlList:urlList,userId:userId},
                                     callbackParameter: "callback",
                                     success: function (data, textStatus, xOptions) {
                                     if(data.succ==true){
                                     showToast("评论成功~");
                                     window.history.go(-1);
                                     }else{
                                     showToast("评论失败~");
                                     }
                                     },
                                     error: function (xOptions, textStatus) {
                                     showToast("评论失败~");
                                     }
                                     });
                             }else{
                             showToast("点评内容不能超过20个字~");
                             return;
                             }
                             }
                             if(param=="guide"){
                             if(comment.length<=20){
                             $.jsonp({
                                     url: 'http://'+url+'/api/guide/comment',
                                     data: {star:star,comment:comment,guideId:id,urlList:urlList,userId:userId},
                                     callbackParameter: "callback",
                                     success: function (data, textStatus, xOptions) {
                                     if(data.succ==true){
                                     showToast("评论成功~");
                                     window.history.go(-1);
                                     }else{
                                     showToast("评论失败~");
                                     }
                                     },
                                     error: function (xOptions, textStatus) {
                                     showToast("评论失败~");
                                     }
                                     });
                             }else{
                             showToast("点评内容不能超过20个字~");
                             return;
                             }
                             }
                             if(param=="photobook"){
                             if(comment.length<=20){
                             $.jsonp({
                                     url: 'http://'+url+'/api/photobook/comment',
                                     data: {star:star,comment:comment,photobookId:id,urlList:urlList,userId:userId},
                                     callbackParameter: "callback",
                                     success: function (data, textStatus, xOptions) {
                                     if(data.succ==true){
                                     showToast("评论成功~");
                                     window.history.go(-1);
                                     }else{
                                     showToast("评论失败~");
                                     }
                                     },
                                     error: function (xOptions, textStatus) {
                                     showToast("评论失败~");
                                     }
                                     });
                             }else{
                             showToast("点评内容不能超过20个字~");
                             return;
                             }
                             }
                             if(param=="jiudian"){
                             if(comment.length<=20){
                             $.jsonp({
                                     url: 'http://'+url+'/api/supplier/comment',
                                     data: {star:star,comment:comment,supplierId:id,urlList:urlList,userId:userId},
                                     callbackParameter: "callback",
                                     success: function (data, textStatus, xOptions) {
                                     if(data.succ==true){
                                     showToast("评论成功~");
                                     window.history.go(-1);
                                     }else{
                                     showToast("评论失败~");
                                     }
                                     },
                                     error: function (xOptions, textStatus) {
                                     showToast("评论失败~");
                                     }
                                     });
                             }else{
                             showToast("点评内容不能超过20个字~");
                             return;
                             }
                             }
                             if(param=="meishi"){
                             if(comment.length<=20){
                             $.jsonp({
                                     url: 'http://'+url+'/api/supplier/comment',
                                     data: {star:star,comment:comment,supplierId:id,urlList:urlList,userId:userId},
                                     callbackParameter: "callback",
                                     success: function (data, textStatus, xOptions) {
                                     if(data.succ==true){
                                     showToast("评论成功~");
                                     window.history.go(-1);
                                     }else{
                                     showToast("评论失败~");
                                     }
                                     },
                                     error: function (xOptions, textStatus) {
                                     showToast("评论失败~");
                                     }
                                     });
                             }else{
                             showToast("点评内容不能超过20个字~");
                             return;
                             }
                             }
                             if(param=="sheying"){
                             if(comment.length<=20){
                             $.jsonp({
                                     url: 'http://'+url+'/api/mapline/comment',
                                     data: {star:star,comment:comment,cameraId:id,urlList:urlList,userId:userId},
                                     callbackParameter: "callback",
                                     success: function (data, textStatus, xOptions) {
                                     if(data.succ==true){
                                     showToast("评论成功~");
                                     window.history.go(-1);
                                     }else{
                                     showToast("评论失败~");
                                     }
                                     },
                                     error: function (xOptions, textStatus) {
                                     showToast("评论失败~");
                                     }
                                     });
                             }else{
                             showToast("点评内容不能超过20个字~");
                             return;
                             }
                             }
                             if(param=="tongyou"){
                             if(comment.length<=20){
                             $.jsonp({
                                     url: 'http://'+url+'/api/sameway/comment',
                                     data: {star:star,comment:comment,samewayId:id,urlList:urlList,userId:userId},
                                     callbackParameter: "callback",
                                     success: function (data, textStatus, xOptions) {
                                     
                                     if(data.succ==true){
                                     showToast("评论成功~");
                                     window.history.go(-1);
                                     }else{
                                     showToast("评论失败~");
                                     }
                                     },
                                     error: function (xOptions, textStatus) {
                                     showToast("评论失败~");
                                     }
                                     });
                             }else{
                             showToast("点评内容不能超过20个字~");
                             return;
                             }
                             }
                             if(param=="yiren"){
                             if(comment.length<=20){
                             $.jsonp({
                                     url: 'http://'+url+'/api/supplier/comment',
                                     data: {star:star,comment:comment,supplierId:id,urlList:urlList,userId:userId},
                                     callbackParameter: "callback",
                                     success: function (data, textStatus, xOptions) {
                                     if(data.succ==true){
                                     showToast("评论成功~");
                                     window.history.go(-1);
                                     }else{
                                     showToast("评论失败~");
                                     }
                                     },
                                     error: function (xOptions, textStatus) {
                                     showToast("评论失败~");
                                     }
                                     });
                             }else{
                             showToast("点评内容不能超过20个字~");
                             return;
                             }
                             }
                             });
    var oStar = document.getElementById("star");
    var aLi = oStar.getElementsByTagName("li");
    var oUl = oStar.getElementsByTagName("ul")[0];
    for (i = 1; i <= aLi.length; i++){
        aLi[i - 1].index = i;
        //鼠标移过显示分数
        aLi[i - 1].onmouseover = function (){
            fnPoint(this.index);
        };
    }
    //评分处理
    function fnPoint(iArg){
        //分数赋值
        iScore = iArg ;
        for (i = 0; i < aLi.length; i++) aLi[i].className = i < iScore ? "on" : "";
    }
    
    //    function getPics(){
    //        var imgs=$(".ppt img");
    //        var paths=[];
    //        $.each(imgs,function(index,ele){
    //            paths.push($(ele).attr('src'));
    //        })
    //        var paths=paths.join(",");
    //        return paths;
    //    }
}

